<template>
	<view class="content">
		<nav-bar title="详情" />
		<view class="add-con">
			<view class="margin">
				<view class="cu-card">
					<view class="card-title">基础信息</view>
					<u-cell-group>
						<u-cell title="开始学习">
							<template #value>
								<select-picker pickerType="time" @pickerChange="pickerChange($event,'kaishixuexi')">
									<view class="flex justify-end">
										<text style="text-align:right"
											v-if="formData.kaishixuexi">{{formData.kaishixuexi}}</text>
										<text v-else class="textInfo">请选择</text>
										<u-icon name="arrow-right" />
									</view>
								</select-picker>
							</template>
						</u-cell>
					</u-cell-group>
					<u-cell title="今日目标">
						<template #label>
							<view class="padding-top-sm">
								<u-textarea v-model="formData.jinrimubiao" placeholder="请输入今日目标"></u-textarea>
							</view>

						</template>
					</u-cell>
					<u-cell title="结束学习" v-if="!isAdd">
						<template #value>
							<select-picker pickerType="time" @pickerChange="pickerChange($event,'jieshuxuexi')">
								<view class="flex justify-end">
									<text style="text-align:right"
										v-if="formData.jieshuxuexi">{{formData.jieshuxuexi}}</text>
									<text v-else class="textInfo">请选择</text>
									<u-icon name="arrow-right" />
								</view>
							</select-picker>
						</template>
					</u-cell>
					
					<u-cell title="打卡人" :value="formData.dakaren">
					</u-cell>
					</u-cell-group>

				</view>

				<view class="padding-tb flex align-center">
					<u-button type="primary" text="保存" @click="formSubmit"></u-button>
					<template v-if="!isAdd">
						<view class="padding-lr-sm"></view>
						<u-button type="error" text="删除" @click="deleteSubmit(formData.id)"></u-button>
					</template>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		submitMinxins,
		detailMinxins
	} from '@/common/mixins/mixins.js'
	import SelectPicker from '@/components/selectPicker.vue'
	import uploadFile from '@/components/uploadFile.vue'
	export default {
		name: 'ClockInAdd',
		desc: '打卡增加,详情，编辑',
		mixins: [submitMinxins, detailMinxins],
		components: {
			SelectPicker,
			uploadFile
		},
		data() {
			return {
				userType: this.$store.state.vuex_userType, //用户类型 1 用户 ，2 医生，3 管理员
				userInfo: this.$store.state.vuex_user, //用户信息
				formData: {},
				rule: [{
					name: "kaishixuexi",
					checkType: "notnull",
					errorMsg: "请选择开始学习时间"
				},{
					name: "jinrimubiao",
					checkType: "notnull",
					errorMsg: "请输入今日目标"
				}, ],
				isAdd: true, //用于判断接口是否是增加
				isEdit: true, //是否可编辑
				urlapi: {
					add: '/qiandaodaka', //增加接口地址
					edit: '/qiandaodaka', //编辑接口
					del: '/qiandaodaka', //删除接口
					detail: '/qiandaodaka', //详情接口
				}
			}
		},
		onLoad(option) {
			// console.log("详情",option,JSON.parse(option.item))
			this.initDatas(option.id)
		},
		methods: {
			initDatas(id) {
				const that = this
				//存在参数 item ，可编辑 否则是增加
				if (id) {
					// const datas = JSON.parse(option.item)
					that.getDetailData(id).then(res => {
						that.formData = {
							...res,
							dakaren:that.userInfo.xuehao
						}
					}) //获取详情
					that.isAdd = false

				} else {
					that.formData = {
						dakaren:that.userInfo.xuehao
					}
					that.isAdd = true
				}
			},
			pickerChange(e, label) {
				this.$set(this.formData, label, uni.$u.timeFormat(e, 'yyyy-mm-dd hh:MM:ss'))
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>